package com.breeze.components.message.secure.record;

import com.breeze.components.message.secure.SecureInvokeDTO;
import com.mybatisflex.annotation.Column;
import com.mybatisflex.annotation.Id;
import com.mybatisflex.annotation.KeyType;
import com.mybatisflex.annotation.Table;
import com.mybatisflex.core.handler.Fastjson2TypeHandler;
import java.io.Serializable;
import java.time.LocalDateTime;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 本地消息记录表
 *
 * @author breeze
 * @since 2023-11-12 12:05:28
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Table("secure_invoke_record")
public class SecureInvokeRecord implements Serializable {

  public static final byte STATUS_WAIT = 1;
  public static final byte STATUS_FAIL = 2;

  @Id(value = "id", keyType = KeyType.Auto)
  private Long id;

  /** 请求快照参数json */
  @Column(value = "secure_invoke_json", typeHandler = Fastjson2TypeHandler.class)
  private SecureInvokeDTO secureInvokeDTO;

  /** 状态 1待执行 2已失败 */
  @Builder.Default private Byte status = SecureInvokeRecord.STATUS_WAIT;

  @Builder.Default private LocalDateTime nextRetryTime = LocalDateTime.now();

  @Builder.Default private Integer retryTimes = 0;

  private Integer maxRetryTimes;

  private String failReason;

  @Column(onInsertValue = "now()")
  private LocalDateTime createTime;

  @Column(onUpdateValue = "now()")
  private LocalDateTime updateTime;
}
